package com.nuonuo.utils;

/**
 * @author duan
 * @version 1.0
 * @date 2023/4/17 11:18
 */
public class UriComparator{


    public static int compareTo(String uri, String location) {
        int len1 = uri.length();
        int len2 = location.length();
        int n = Math.min(len1, len2);
        char[] v1 = uri.toCharArray();
        char[] v2 = location.toCharArray();

        int k = 0;
        while (n > 0) {
            char c1 = v1[k];
            char c2 = v2[k];

            if (c1 == c2) {
                if (c1 > 0) {
                    n--;
                    k++;
                    continue;
                }
                return 0;
            }
            if (c1 == 0 || c2 == 0) {
                return c1 - c2;
            }
            c1 = (c1 == '/') ? 0: c1;
            c2 = (c2 == '/') ? 0: c2;
            return c1 - c2;
        }
        return 0;
    }

    public static void main(String[] args) {
        String node = "instead/order/allow/findOrderDetail.do";
        // = 0
        String uri1 = "instead/order/allow/findOrderDetail.do";
        // < 0
        String uri2 = "instead/order/allow/deleteOrderById.do";
        // < 0
        String uri3 = "api/generation/platform/data/synchronization";
        // > 0
        String uri4 = "instead/v2/lanApi/message";
        // > 0
        String uri5 = "instead/v2/lanApi/customer";
        int result1 = compareTo(uri1, node);
        int result2 = compareTo(uri2, node);
        int result3 = compareTo(uri3, node);
        int result4 = compareTo(uri4, node);
        int result5 = compareTo(uri5, node);
        System.out.println("result1 = 0: " + result1);
        System.out.println("result2 < 0: " + result2);
        System.out.println("result3 < 0: " + result3);
        System.out.println("result4 > 0: " + result4);
        System.out.println("result5 > 0: " + result5);
    }
}
